import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const router = new Router({
	routes: [
		{
			path: "/",
			name: "home",
			meta: {
				title: "哔哩哔哩直播姬",
			},
			component: require("@/components/Home").default,
		},
		{
			path: "/setting",
			name: "setting",
			meta: {
				title: "哔哩哔哩直播姬-设置",
			},
			component: require("@/components/setting/Setting").default,
		},
		{
			path: "/keywords",
			name: "keywords",
			meta: {
				openKeywrod: true,
				automaticReplyTitle: "自动回复关键字",
				soundEffectTitle: "触发音效关键字",
			},
			component: require("@/components/keywords/Keywords").default,
		},
		{
			path: "/music",
			name: "music",
			meta: {
				title: "哔哩哔哩直播姬-点歌姬",
			},
			component: require("@/components/music/Music").default,
		},
		{
			path: "/barrage",
			name: "barrage",
			meta: {
				title: "哔哩哔哩直播姬-弹幕姬",
			},
			component: require("@/components/barrage/Barrage").default,
		},
		{
			path: "*",
			redirect: "/",
		},
	],
});

export default router;

router.beforeEach((to, from, next) => {
	if (to.meta.openKeywrod) {
		!!+localStorage.getItem("liveKeyword")
			? (document.title = to.meta.automaticReplyTitle)
			: (document.title = to.meta.soundEffectTitle);
	} else {
		document.title = to.meta.title;
	}

	next();
});
